<!-- 重点用能设备管理-设备台账管理 -->
<script setup lang="tsx">
import { ElTag } from 'element-plus'
import { SearchForm } from './components'
import { defaultPagingParams } from './index'
import type { KeyEquipmentInfo, TableColumn } from '@/types'
import { keyEquipmentApi } from '@/api'
// ------------------use------------------
// #region
const { withLoading, loading } = useDefineLoading()
const [tableData, setTableData] = useState<
  KeyEquipmentInfo[]
>([])
const [total, setTotal] = useState<number>(0)
// #endregion
// ------------------静态变量------------------
// #region
const columns: TableColumn<KeyEquipmentInfo>[] = [
  {
    key: uuid(),
    type: 'index',
    width: '80',
    label: '序号',
  },
  {
    key: uuid(),
    label: '设备名称',
    prop: 'deviceName',
  },
  {
    key: uuid(),
    label: '设备编码',
    prop: 'deviceModel',
  },
  {
    key: uuid(),
    label: '设备型号',
    prop: 'deviceNumber',
  },
  {
    key: uuid(),
    label: '淘汰批次',
    render() {
      return '淘汰目录（第二批）'
    },
  },
  {
    key: uuid(),
    label: '状态 ',
    render({ row }) {
      const s = h(ElTag, null, { default: () => '正常' })
      const e = h(
        ElTag,
        {
          type: 'danger',
        },
        {
          default: () => '故障',
        },
      )
      return row.status ? e : s
    },
  },
]
// #endregion
// ------------------动态变量------------------
// #region

// #endregion
// ------------------ref-----------
// #region
const pagingParams = ref({
  ...defaultPagingParams,
})
// #endregion
// ------------------reactive------
// #region

// #endregion
// ------------------computed------
// #region
// #endregion
// ------------------生命周期------------------
// #region
onMounted(() => {
  getTableData()
})
// #endregion
// ------------------内置方法---------------------
// #region

// #endregion
// ------------------方法---------------------
// #region
async function getTableData() {
  const params = { ...pagingParams.value }
  removeUnnecessaryParams(params)
  const { data: res } = await withLoading(
    keyEquipmentApi.queryList,
  )(params)
  if (!res) {
    setTotal(0)
    setTableData([])
    return
  }
  const { total, records } = res
  setTotal(total)
  setTableData(records!)
}

// #endregion
</script>

<template>
  <div
    class="padding-sm flex-direction flex align-end container"
  >
    <view-table
      :loading="loading"
      :columns="columns"
      :data="tableData"
    >
      <template #actions>
        <SearchForm
          v-model="pagingParams"
          @search="getTableData"
          @reset="getTableData"
        />
      </template>
    </view-table>

    <!-- 分页 -->
    <ListsPagination
      v-model:page-num="pagingParams.pageNumber"
      v-model:page-size="pagingParams.pageSize"
      :total="total"
      @current-change="getTableData"
      @size-change="getTableData"
    />
  </div>
</template>

<style lang="scss" scoped>
//------------------组件样式------------------
//-------------样式穿透-------------
</style>
